package com.liuziqiang.demo.Controller;

import com.liuziqiang.demo.Dto.JsonResponse;
import com.liuziqiang.demo.Dto.School;
import com.liuziqiang.demo.Mapper.SchoolDao;
import com.liuziqiang.demo.Dto.SchoolExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("school")
public class UserController {

    @Autowired
    private SchoolDao schoolDao;

    @PostMapping("getData")
    @CrossOrigin
    public JsonResponse<List> List(@RequestBody School school){
        JsonResponse<List> json = new JsonResponse<>();

        String type = school.getType();
        String schoolName = school.getSchoolName();
        HashMap<String, String> typeMap = new HashMap<>();
        typeMap.put("","");
        typeMap.put("1","%一流大学%");
        typeMap.put("2","%一流学科%");
        typeMap.put("3","%985%");
        typeMap.put("4","%211%");

        String city = school.getLocation();

        HashMap<String, String> cityMap = new HashMap<>();
        cityMap.put("","");
        cityMap.put("1-1","%北京市%");
        cityMap.put("1-2","%四川省%");
        cityMap.put("1-3","%天津市%");
        cityMap.put("1-4","%河北省%");
        cityMap.put("1-5","%山西省%");
        cityMap.put("1-6","%内蒙古自治区%");
        cityMap.put("1-7","%辽宁省%");
        cityMap.put("1-8","%吉林省%");
        cityMap.put("1-9","%黑龙江省%");
        cityMap.put("1-10","%上海市%");
        cityMap.put("1-11","%江苏省%");

        cityMap.put("1-12","%浙江省%");
        cityMap.put("1-13","%安徽省%");
        cityMap.put("1-14","%福建省%");
        cityMap.put("1-15","%江西省%");
        cityMap.put("1-16","%山东省%");

        cityMap.put("1-17","%河南省%");
        cityMap.put("1-18","%湖北省%");
        cityMap.put("1-19","%湖南省%");
        cityMap.put("1-20","%广东省%");
        cityMap.put("1-21","%广西壮族自治区%");

        cityMap.put("1-22","%海南省%");
        cityMap.put("1-23","%重庆市%");
        cityMap.put("1-24","%贵州省%");
        cityMap.put("1-25","%云南省%");
        cityMap.put("1-26","%西藏自治区%");

        cityMap.put("1-27","%陕西省%");
        cityMap.put("1-28","%甘肃省%");
        cityMap.put("1-29","%青海省%");
        cityMap.put("1-30","%宁夏回族自治区%");
        cityMap.put("1-31","%新疆维吾尔族自治区%");





        if(type!="") {
            SchoolExample schoolExample2 = new SchoolExample();
            SchoolExample.Criteria criteria =schoolExample2.createCriteria();
            criteria.andTypeLike(typeMap.get(type));


            List<School> schools = schoolDao.selectByExample(schoolExample2);
            json.setResult(schools);

            return json;
        }

        if(city!="") {

            SchoolExample schoolExample1 = new SchoolExample();
            SchoolExample.Criteria criteria1 =schoolExample1.createCriteria();
            criteria1.andLocationLike(cityMap.get(city));



            List<School> schoolss = schoolDao.selectByExample(schoolExample1);
            json.setResult(schoolss);

            return json;
        }
        if (schoolName!= "" ){
            SchoolExample schoolExample3 = new SchoolExample();
            SchoolExample.Criteria criteria =schoolExample3.createCriteria();


            criteria.andSchoolNameLike("%" + schoolName + "%");
            List<School> schools = schoolDao.selectByExample(schoolExample3);
            json.setResult(schools);

            return json;

        }

        SchoolExample schoolExample = new SchoolExample();
        SchoolExample.Criteria criteria =schoolExample.createCriteria();




        List<School> schools = schoolDao.selectByExample(schoolExample);
        json.setResult(schools);

        return json;


    }
}
